//
//  XNBaseNavigationViewController.m
//  XINNingOA
//
//  Created by samuel on 2021/7/14.
//

#import "XNBaseNavigationViewController.h"

@interface XNBaseNavigationViewController ()

@end

@implementation XNBaseNavigationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    if (@available(iOS 15.0, *)) {
        UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];
        barApp.backgroundColor = [UIColor colorWithHexString:@"#358AFF"];;
        barApp.titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
                                      [UIColor whiteColor],NSForegroundColorAttributeName,
                                                               [UIFont systemFontOfSize:18 weight:UIFontWeightBold],NSFontAttributeName,nil];
        self.navigationBar.scrollEdgeAppearance = barApp;
        self.navigationBar.standardAppearance = barApp;

    }else{
        self.navigationBar.barTintColor = [UIColor colorWithHexString:@"#358AFF"];;
        [self.navigationBar setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
                                                     [UIColor whiteColor],NSForegroundColorAttributeName,
                                                                              [UIFont systemFontOfSize:18 weight:UIFontWeightBold],NSFontAttributeName,nil]];
    }

    // Do any additional setup after loading the view.
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
//    self.topViewController.hidesBottomBarWhenPushed = YES;
    if (self.viewControllers.count >= 1) {
        viewController.hidesBottomBarWhenPushed = YES;
    }

    [super pushViewController:viewController animated:animated];
}


- (UIView *)gradientView
{
    CGRect gradientRect = CGRectMake(0.f, 0.f, [UIScreen mainScreen].bounds.size.width, [[UIApplication sharedApplication] statusBarFrame].size.height + self.navigationBar.frame.size.height);
    
    UIView *gradientView = [[UIView alloc] initWithFrame:gradientRect];
    
    CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
    
    gradientLayer.frame = gradientRect;
    gradientLayer.colors = @[(__bridge id)[UIColor colorWithHexString:@"#5B89D7"].CGColor,(__bridge id)[UIColor colorWithHexString:@"#2F3281"].CGColor];
    // 通过修改 startPoint 和 endPoint 调整渐变方向
    gradientLayer.startPoint = CGPointMake(0, 1);
    gradientLayer.endPoint = CGPointMake(1, 1);
    
    [gradientView.layer addSublayer:gradientLayer];
    
    return gradientView;
}
 
- (UIImage *)makeImageWithView:(UIView *)view
{
    CGSize size = view.bounds.size;
    
    /**
     * size: 表示区域大小
     * opaque: 是否透明, NO - 半透明, YES - 非透明
     * scale: 屏幕密度(几倍像素)
     */
    UIGraphicsBeginImageContextWithOptions(size, NO, [UIScreen mainScreen].scale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}


@end
